<?php
use PHPUnit\Framework\TestCase;
use \JC\CodeWars\BaseQues;

/**
 * Created by PhpStorm.
 * User: jochen
 * Date: 2016/12/23
 * Time: 下午6:34
 */
class BaseQuesSpec extends TestCase
{
    /** @var  BaseQues $que */
    protected $que;
    protected function SetUp() {
        $this->que = new BaseQues();
    }

    public function testSum0ToN() {
        $last = 6;
        $r = $this->que->sumNumberFrom0ToN($last);
        $this->assertEquals('0+1+2+3+4+5+6 = 21', $r);
        $r = $this->que->sumNumberFrom0ToN(-1);
        $this->assertEquals('-1 < 0', $r);
        $r = $this->que->sumNumberFrom0ToN(0);
        $this->assertEquals('0=0', $r);
    }

    public function testBitCounting() {
        $number = 164;
        $count = $this->que->bitCounting($number);
        $str = base_convert($number, 10, 2);
        echo $str;
        echo PHP_EOL;
        echo $count;
    }

    private function revTest($actual, $expected) {
        $this->assertEquals($expected, $actual);
    }
    public function testMaxRot() {
        $this->revTest($this->que->maxRot(38458215), 85821534);
        $this->revTest($this->que->maxRot(195881031), 988103115);
        $this->revTest($this->que->maxRot(896219342), 962193428);
    }

    public function testAccum() {
        $revTest = function($actual, $expected) {
            $this->assertEquals($expected, $actual);
        };

        $revTest($this->que->accum("ZpglnRxqenU"), "Z-Pp-Ggg-Llll-Nnnnn-Rrrrrr-Xxxxxxx-Qqqqqqqq-Eeeeeeeee-Nnnnnnnnnn-Uuuuuuuuuuu");
        $revTest($this->que->accum("NyffsGeyylB"), "N-Yy-Fff-Ffff-Sssss-Gggggg-Eeeeeee-Yyyyyyyy-Yyyyyyyyy-Llllllllll-Bbbbbbbbbbb");
        $revTest($this->que->accum("MjtkuBovqrU"), "M-Jj-Ttt-Kkkk-Uuuuu-Bbbbbb-Ooooooo-Vvvvvvvv-Qqqqqqqqq-Rrrrrrrrrr-Uuuuuuuuuuu");
        $revTest($this->que->accum("EvidjUnokmM"), "E-Vv-Iii-Dddd-Jjjjj-Uuuuuu-Nnnnnnn-Oooooooo-Kkkkkkkkk-Mmmmmmmmmm-Mmmmmmmmmmm");
    }

    public function testExample()
    {
        $number = 1234123;

    }

}
